package net.cyue.web.easyquery.core.http.data;

import java.util.Objects;

public class QueryParameter {
    public enum Type {
        ANY,
        STR,
        STRING,
        INT,
        INTEGER,
        LONG,
        FLOAT,
        DOUBLE,
        NUMBER,
        BOOL,
        BOOLEAN,
    }

    private final String name;
    private final Type type;
    private final String description;
    private final boolean required;
    private Object defaultValue;

    public QueryParameter(String name) {
        this(name, Type.ANY);
    }
    public QueryParameter(String name, Object defaultValue) {
        this(name, Type.ANY, false, defaultValue);
    }

    public QueryParameter(String name, boolean required) {
        this(name, Type.ANY, required);
    }
    public QueryParameter(String name, boolean required, Object defaultValue) {
        this(name, Type.ANY, required, defaultValue);
    }

    public QueryParameter(String name, Type type) {
        this(name, type, null);
    }
    public QueryParameter(String name, Type type, Object defaultValue) {
        this(name, type, false, defaultValue);
    }

    public QueryParameter(String name, Type type, boolean required) {
        this(name, type, required, null);
    }
    public QueryParameter(String name, Type type, boolean required, Object defaultValue) {
        this(name, type, null, required, defaultValue);
    }

    public QueryParameter(String name, Type type, String description) {
        this(name, type, description, false);
    }
    public QueryParameter(String name, Type type, String description, boolean required) {
        this(name, type, description, required, null);
    }

    public QueryParameter(
        String name,
        Type type,
        String description,
        boolean required,
        Object defaultValue
    ) {
        this.name = name;
        this.type = type;
        this.description = description;
        this.required = required;
        this.defaultValue = defaultValue;
    }

    @Override
    public int hashCode() {
        return Objects.hash(this.name);
    }
    @Override
    public boolean equals(Object obj) {
        if (obj == this) {
            return true;
        }
        if (!(obj instanceof QueryParameter)) {
            return false;
        }
        QueryParameter parameter = (QueryParameter) obj;
        return Objects.equals(this.name, parameter.name);
    }

    public String getName() {
        return this.name;
    }
    public Type getType() {
        return this.type;
    }
    public String getDescription() {
        return this.description;
    }
    public boolean isRequired() {
        return this.required;
    }
    public Object getDefaultValue() {
        return this.defaultValue;
    }

    public void setDefaultValue(Object defaultValue) {
        this.defaultValue = defaultValue;
    }
}
